package com.study.suanfa.poke;

import com.sun.scenario.animation.shared.ClipEnvelope;

/**
 * @description: Poker 扑克玩法模拟
 * @date: 2021/1/18 15:13
 * @author: hcm
 * @version: 1.0
 */
public class Poker {

    public static void main(String[] args) {
        Poker poker = new Poker();
        poker.shuffle();
        Card card = poker.deal(0);
        Card card1 = new Card("红心",1);
        System.out.println(card);
        System.out.println(card1);
    }

    private static String[] suites = {"黑桃","红桃","草花","方块"};
    private static int[] faces = {1,2,3,4,5,6,7,8,9,10,11,12,13};

    private Card[] cards;

    public Poker() {
       cards = new Card[52];
        for (int i = 0; i < suites.length; i++) {
            for (int j = 0; j < faces.length; j++) {
                cards[i*13+j] = new Card(suites[i],faces[j]);
            }
        }
    }

    /**
     * 洗牌（随机）
     */
    public void shuffle(){
        for (int i = 0,len=cards.length; i <len ; i++) {
            int index = (int) (Math.random()*len);
            Card temp = cards[index];
            cards[index] = cards[i];
            cards[i] = temp;
        }
    }
    /**
     * 发牌
     */
    public Card deal(int index){
        return cards[index];
    }
}

class Card{
    /**
     * 花色
     */
    private String suite;
    /**
     * 点数
     */
    private int face;

    public Card(String suite , int face){
        this.suite = suite;
        this.face = face;
    }

    @Override
    public String toString() {
        String faceStr = "";
        switch(face) {
            case 1: faceStr = "A"; break;
            case 11: faceStr = "J"; break;
            case 12: faceStr = "Q"; break;
            case 13: faceStr = "K"; break;
            default: faceStr = String.valueOf(face);
        }
        return suite + faceStr;
    }
}
